/**
 * Created by 功振 on 2016/2/20.
 */
angular.module("Portal").directive("ngReadPhone", ["userInfoService", function (userInfoService) {
    return {
        restrict: 'A',
        require: 'ngModel',
        link: function (scope, element, attrs, ngModel) {
            element.bind('blur', function (e) {
                if (!ngModel || !element.val()) return;
                var currentValue = element.val();
                console.log("currentValue:" + currentValue);
                /*  AuthService.checkUniqueValue(keyProperty.key, keyProperty.property, currentValue)
                 .then(function (unique) {
                 //Ensure value that being checked hasn't changed
                 //since the Ajax call was made
                 if (currentValue == element.val()) {
                 console.log('unique = '+unique);
                 ngModel.$setValidity('unique', unique);
                 scope.$broadcast('show-errors-check-validity');
                 }
                 });*/
                userInfoService.getUserInfo(currentValue).then(function (response) {
                    var phonenumber = response.data;
                    scope.phoneNumber = phonenumber;
                    scope.fakePhoneNumber = phonenumber.substring(0,3) + "****" + phonenumber.substring(7,11);
                    console.log("phonenumber: " + phonenumber);
                }, function (response) {
                    console.log("Get phonenumber failed");
                });

            });
        }
    }
}]);